home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / Jooky / jookysock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-01  |  2.2 KB  |  99 lines

  1. #include "includes.h"
  2. #include "defines.h"
  3. #include "funcs.h"
  4.  
  5. void jookysock(dir, title)
  6.     char *dir ;
  7.     char *title ;
  8. {
  9.     their_size=sizeof(struct sockaddr_in);
  10.     if ((new_fd=accept(fd,&their_addr,&their_size))!=-1)
  11.     {
  12.         if (!fork()) /* this is the kid */
  13.         {
  14.  
  15.             memset(argstart,0,pssize);
  16.             sprintf((char *)argstart,"jookysockd [port %d] [%s] [%s]",port,dir,title);
  17.             instring=calloc(1,256);
  18.             if (usepasswd==1)
  19.             {
  20.                 memset(guess,0,80);
  21.                 write(new_fd,"password: ",10);
  22.                 read (new_fd,guess,80);
  23.                 if (strncmp(guess,password,strlen(password))!=0)
  24.                 {
  25.                     close (new_fd);
  26.                     exit(0) ;
  27.                 }
  28.             } else {
  29.                 write(new_fd,"welcome!\n",9);
  30.             }
  31.             read(new_fd,instring,10);
  32.     
  33.             if (strncmp(instring,"quer",4)==0)
  34.             {
  35.                 stringy=calloc(1,256);
  36.                 sprintf(stringy,"\n\n\nmp3 directory : %s\n\nmp3 title     : %s\n\n",dir,title);
  37.                 write(new_fd,stringy,strlen(stringy));
  38.                 free(stringy);
  39.             }
  40.     
  41.             if (strncmp(instring,"next",4)==0)
  42.             {
  43.                 kill(getppid(),NEXT);
  44.             }
  45.  
  46.             if (strncmp(instring,"repe",4)==0)
  47.             {
  48.                 kill(getppid(),PREV);
  49.             }
  50.     
  51.             if (strncmp(instring,"prev",4)==0)
  52.             {
  53.                 kill(getppid(),PREV);
  54.                 usleep(250000);
  55.                 kill(getppid(),PREV);
  56.             }
  57.     
  58.             if (strncmp(instring,"paus",4)==0)
  59.             {
  60.                 kill(getppid(),PAUSE);
  61.             }
  62.     
  63.             if (strncmp(instring,"resu",4)==0)
  64.             {
  65.                 kill(getppid(),RESUME);
  66.             }
  67.     
  68.             if (strncmp(instring,"quit",4)==0)
  69.             {
  70.                 kill(getppid(),QUIT);
  71.             }
  72.     
  73.             if (strncmp(instring,"stop",4)==0)
  74.             {
  75.                 kill(getppid(),QUIT);
  76.             }
  77.  
  78.             if (strncmp(instring,"help",4)==0)
  79.             {
  80.                 write (new_fd,"query:  current dir and title\n",31);
  81.                 write (new_fd,"next:   next title\n",19);
  82.                 write (new_fd,"prev:   previous title\n",23);
  83.                 write (new_fd,"repeat: restart current title\n",30);
  84.                 write (new_fd,"pause:  pause playback\n",23);
  85.                 write (new_fd,"resume: resume playback\n",24);
  86.                 write (new_fd,"quit:   terminate playback\n",27);
  87.                 write (new_fd,"stop:   terminate playback\n",27);
  88.             }
  89.             free(instring);
  90.             close (new_fd);
  91.             exit(0) ;
  92.         } else
  93.         {
  94.             close(new_fd);
  95.             while(waitpid(-1,NULL,WNOHANG) > 0); /* clean up brats */
  96.         }
  97.     }
  98. }
  99.